package servlets;

import java.io.*;
import java.sql.Connection;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;

import dataAccess.ConnectionDB;
import dataAccess.OrdenesCompletasDAO;
import bussinesObjetcs.OrdenBean;




/** Servlet that reads a customer ID and displays
 *  information on the account balance of the customer
 *  who has that ID.
 *  <p>
 *  From <a href="http://courses.coreservlets.com/Course-Materials/">the
 *  coreservlets.com tutorials on servlets, JSP, Struts, JSF, Ajax, GWT, 
 *  Spring, Hibernate/JPA, and Java programming</a>.
 */

@WebServlet("/AddServletOrdenesCompletas")
public class AddServletOrdenesCompletas extends HttpServlet {


/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

@Override

public void doPost (HttpServletRequest request,
		            HttpServletResponse response)
	  throws ServletException, IOException 
{ 
doGet(request, response); 
}
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
	
	String idorden = request.getParameter("idorden");
	String fecha = request.getParameter("fecha");
	String costo = request.getParameter("costo");
	String turno = request.getParameter("turno");
	String formapago= request.getParameter("formapago");
	String status= request.getParameter("status");
	
	
	
	//crear el bean
	OrdenBean orden = new OrdenBean();
	
	orden.setIdorden(idorden);
	orden.setFecha(fecha);
	orden.setCosto(costo);
	orden.setTurno(turno);
	orden.setFormapago(formapago);
	orden.setStatus(status);
		
	//Guardar instacia en base de datos
	ConnectionDB connectionDB = new ConnectionDB();
	Connection connection = connectionDB.getConnectionDB();
	
	OrdenesCompletasDAO ordenDao = new OrdenesCompletasDAO(connection);
	ordenDao.addOrden(orden);
	  
//    String customerId = request.getParameter("customerId");
//    CustomerLookupService service = new CustomerSimpleMap();
//    Customer customer = service.findCustomer(customerId);  // OK to pass null or empty String to findCustomer
    request.setAttribute("orden", orden);
    RequestDispatcher dispatcher= request.getRequestDispatcher("displayOrdenesCompletas.jsp");
    dispatcher.forward(request, response);
    
   // protected void doPost()
  }
}